import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;


public class ConfigState extends State{
	private static final long serialVersionUID = 3352197009780906978L;
	
	JList virusList, mapList;
	JRadioButton radioEasy, radioNormal, radioHard;
	
	public ConfigState(){
		SpritePanel sp = getSpritePanel();
		Sprite background = new Sprite();
		background.setImg(sp.loadImage("background.png").getImage());
		sp.getSprites().add(background);
		setLayout(new BorderLayout());
		
		JPanel upperPanel = ComponentFactory.createPanel("");
		
		//upperPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 20, 0);
		upperPanel.setLayout(flowLayout);
		//Back dugme
		JButton backButton = new JButton("Back");
		backButton.setPreferredSize(new Dimension(100, 30));
		backButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				Application.getStateManager().changeState(new MainMenu());
			}
		});
		upperPanel.add(backButton);
		//upperPanel.setPreferredSize(new Dimension(640,80));
		//Tezina
		JPanel tezinaPanel = ComponentFactory.createPanel("Tezina");
		tezinaPanel.setOpaque(false);
		tezinaPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 0));
		tezinaPanel.setPreferredSize(new Dimension(350,50));
		ButtonGroup rbGroup = new ButtonGroup();
		radioEasy = new JRadioButton("Easy");
		radioEasy.setOpaque(false);
		rbGroup.add(radioEasy);
		tezinaPanel.add(radioEasy);
		radioNormal = new JRadioButton("Normal");
		radioNormal.setOpaque(false);
		radioNormal.setSelected(true);
		rbGroup.add(radioNormal);
		tezinaPanel.add(radioNormal);
		radioHard = new JRadioButton("Hard");
		radioHard.setOpaque(false);
		rbGroup.add(radioHard);
		tezinaPanel.add(radioHard);
		/*TitledBorder title = BorderFactory.createTitledBorder("Tezina");
		title.setTitleJustification(TitledBorder.CENTER);
		tezinaPanel.setBorder(title);*/
		
		upperPanel.add(tezinaPanel);
		//Play dugme
		JButton playButton = new JButton("Play");
		playButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				Application.getStateManager().changeState(new GameState());
			}
		});
		playButton.setPreferredSize(new Dimension(100, 30));
		upperPanel.add(playButton);
		
		add(new AlphaContainer(upperPanel), BorderLayout.SOUTH);
		//Virus panel
		JPanel virusSelectionPanel = ComponentFactory.createPanel("Izaberi virus");
		virusSelectionPanel.setLayout(new BorderLayout());
		virusSelectionPanel.setPreferredSize(new Dimension(270, 300));
		
		DefaultListModel virusListModel = new DefaultListModel();
		for (int i = 1; i < 7; i++)
			virusListModel.addElement("Virus " + i);
		
		virusList = new JList(virusListModel);
		JScrollPane scrollPane = new JScrollPane(virusList);
		scrollPane.setPreferredSize(new Dimension(180, 120));
		
		virusSelectionPanel.add(scrollPane, BorderLayout.SOUTH);
		
		ImageIcon ii = new ImageIcon(this.getClass().getResource("virus.png"));
		virusSelectionPanel.add(new JLabel(ii),BorderLayout.NORTH);
		
		add(virusSelectionPanel, BorderLayout.WEST);
		
		//Map panel
		JPanel mapSelectionPanel = ComponentFactory.createPanel("Izaberi mapu");
		mapSelectionPanel.setLayout(new BorderLayout());
		mapSelectionPanel.setPreferredSize(new Dimension(340, 300));
		
		DefaultListModel mapListModel = new DefaultListModel();
		for (int i = 1; i < 30; i++)
			mapListModel.addElement("Mapa " + i);
		
		mapList = new JList(mapListModel);
		scrollPane = new JScrollPane(mapList);
		scrollPane.setPreferredSize(new Dimension(120, 120));
		
		mapSelectionPanel.add(scrollPane, BorderLayout.SOUTH);
		
		ii = new ImageIcon(this.getClass().getResource("mapa.png"));
		mapSelectionPanel.add(new JLabel(ii),BorderLayout.NORTH);
		
		add(mapSelectionPanel, BorderLayout.EAST);
		
		
	}

}
